let that;
let api = require("../../mars/services/api.js");
import config from '../../mars/conf/config'
Page({
  /**
   * 页面的初始数据
   */
  data: {
    host: config.domain,
    id: "",
    nickname: "",
    hiddenShareBtn:false,
    punchInfo: {
      created_time: "",
      user_name: "",
      waist: "",
      weight: "",
      description: ""
    },
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    that = this;
    if (options.id) {
      that.setData({
        id: options.id,
        nickname: options.nickname || wx.getStorageSync("user").user_name
      });
      that.getPunchRecordById(options.id);
    }

    that.setData({
      hiddenShareBtn: !!options.fromShare
    });
    wx.showShareMenu({
      withShareTicket: true
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function(e) {
    let nickname = that.data.nickname;
    return {
      title: '培养易瘦好习惯打卡',
      path: '/pages/sharePunchInfo/sharePunchInfo?fromShare=1&id=' + that.data.id + "&nickname=" + nickname
    }
  },
  getPunchRecordById(id) {
    api.WxRequest(api.getPunchRecordById, {
      id: id
    }, function(res) {
      if (res.status) return;
      that.setData({
        punchInfo: res.data
      });
    });
  },
  relauchToIndex() {
    wx.reLaunch({
      url: '/pages/calorieIndex/calorieIndex',
    });
  },
  navigateToPunch() {
    wx.reLaunch({
      url: '/pages/activityIndex/activityIndex',
    });
  }
})